package method4;

/**
 * 双检查，线程安全
 * 优点：灵活
 * 缺点：稍微复杂点
 */
public class Singleton {

	private static Singleton instance;
	
	private Singleton(){}

	public static Singleton getInstance(){
		if (instance == null) {
			synchronized (instance) {
				if (instance == null) {
					instance = new Singleton();
				}
			}
		}
		return instance;
	}
}
